define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'onaccount_manage/onaccountlog/index' + location.search,
                    add_url: 'onaccount_manage/onaccountlog/add',
//                  edit_url: 'onaccount_manage/onaccountlog/edit',
//                  del_url: 'onaccount_manage/onaccountlog/del',
                    multi_url: 'onaccount_manage/onaccountlog/multi',
                    import_url: 'onaccount_manage/onaccountlog/import',
                    show_url: 'onaccount_manage/onaccountlog/show',
                    table: 'onaccountlog',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
//                      {field: 'id', title: __('Id')},
//                      {field: 'agent_id', title: __('Agent_id')},
//                      {field: 'store_no', title: __('store_no')},
                        {field: 'on_no', title: __('单号')},
                        {field: 'onaccount.company_name', title: __('挂账单位')},
                        {field: 'onaccount.contacts', title: __('挂账人')},
                        {field: 'onaccount.mobile', title: __('联系方式')},
                        {field: 'typevalue', title: __('类型')},
                        {field: 'use_amount', title: __('金额'), operate:'BETWEEN'},
                        {field: 'statusvalue', title: __('状态'), searchList: {"0":__('未归还'),"1":__('已归还'),"2":__('部分归还')}, formatter: Table.api.formatter.status},
                        {field: 'remark', title: __('Remark'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons: [{
                                
					            name: 'show',
						            text: __('归还'),
						            title: __('归还'),
						            classname: 'btn-success btn btn-xs btn-primary btn-dialog',
						            icon: 'fa fa-magic',
						            url: 'onaccount_manage/onaccountlog/show',
//						            confirm: '确认归还',
						             visible: function (row) {
						             	console.log(row);
                                           // 自定义按钮 动态是否显示
                                           if (row.type == 1&&(row.status == 0||row.status == 2)) {
                                               return true;
                                           }
                                           
                                           
                                           return false;
                                      },
						            success: function (data, ret) {
						                Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
						                //如果需要阻止成功提示，则必须使用return false;
						                //return false;
						            },
						            error: function (data, ret) {
						                console.log(data, ret);
						                Layer.alert(ret.msg);
						                return false;
						            }


                            }], formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        show: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
